<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box div{
            display: inline-block;
            background-color: black;
            width: 50px;
            height: 50px;
            font-size: 25px;
            line-height: 50px;
            color:white;
            text-align: center;
        }
        .box{
            position: absolute;
            top: 200px;
            left: 200px;
        }
    </style>
</head>
<body>
    <div class="box">
            <div class="hour">1</div>
            <div class="min">2</div>
            <div class="sec">3</div>
    </div>
    <script>
        var hour =document.querySelector('.hour');
        var min = document.querySelector('.min');
        var sec = document.querySelector('.sec');
        var inputTime =+new Date('2021-3-8 23:00:00');
        //开启定时器
        countTime(); //先调用一次函数，第一次刷新就可以出来
        setInterval(countTime,1000);
        function countTime(){
            var nowTime =+new Date();
            var times=(inputTime-nowTime)/1000;
            var h=parseInt(times/60/60%24);
            h=h<10?'0'+h:h;
            hour.innerHTML=h;//赋值参数
            var m =parseInt(times/60%60);
            m=m<10?'0'+m:m;
            min.innerHTML=m;//
            var s = parseInt(times%60);
            s=s<10?'0'+s:s;
            sec.innerHTML=s;//
        }
        
    </script>
</body>
</html>